import { USER, status_background_color, set_isConversation, set_conversationOffer, set_webRtcData } from './actionTypes';

// interface DefaultRedux {
//   [propsName: string]: any;
//   statusBarBackgroundColor: string;
//   user: User;
// }
let defaultState: DefaultRedux = {
  // 用户信息
  user: {
    username: '', // 用户名
  },
  statusBarBackgroundColor: '#000', //状态栏背景色
  isConversation: false, // 是否显示通话组件
  conversationOffer: false, // 是否是本人发起通话
  // webRtc用到的数据
  webRtcData: {
    fromUser: '',
    toUser: '',
  },
};

interface Action {
  type: string;
  value: any;
}
export default (state = defaultState, action: Action) => {
  const { type, value } = action;
  // 设置登录用户信息
  switch (type) {
    case USER:
      return { ...state, user: { ...state.user, ...value } };
    case status_background_color:
      return { ...state, statusBarBackgroundColor: value };
    case set_isConversation:
      return { ...state, isConversation: value };
    case set_conversationOffer:
      return { ...state, conversationOffer: value };
    case set_webRtcData:
      return { ...state, webRtcData: { ...state.webRtcData, ...value } };
    default:
      return state;
  }
};
